<#include "/admin/_inc/_head.html"/>
<#include "/admin/_inc/_layout.html" />
<!DOCTYPE html>
<html lang="en">

<head>
	<@head />
</head>

<body>
	<@layout>
		<nav class="breadcrumb">
			<!-- <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 管理员列表 -->
			<a class="btn btn-success btn-refresh radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
			 title="刷新">
				<i class="Hui-iconfont">&#xe68f;</i>
			</a>
		</nav>
		<div class="pd-20">
			<div class="text-l">
				<form id="query_form">
					<!--<input type="text" class="input-text" style="width:250px" placeholder="输入名称" id="" name="name">
            <button type="button" class="btn btn-success" id="btn_query" ><i class="Hui-iconfont">&#xe665;</i> 查询</button>-->
				</form>
			</div>

			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a href="javascript:;" onclick="tgridObj.add();" class="btn btn-primary radius">
						<i class="Hui-iconfont">&#xe600;</i> 添加</a>
					<a href="javascript:;" onclick="tgridObj.edit();" class="btn btn-primary radius">
						<i class="Hui-iconfont">&#xe60c;</i> 编辑</a>
					<a href="javascript:;" onclick="tgridObj.del();" class="btn btn-danger radius">
						<i class="Hui-iconfont">&#xe605;</i>删除</a>
				</span>
				<span class="r">共有数据：
					<strong class="total">0</strong> 条</span>
			</div>
			<table id="datatable"></table>
			<div id="pagination" class="cl pd-10 r"></div>


		</div>
	</@layout>

	<@tablejs />
	<script type="text/javascript">

		$(function () {

			$('#btn_query').click(function (e) {
				var params = {};
				params = $('#query_form').serializeJSON();

				$('#datatable').tgrid('load', params);
			})
			tgridObj.init();

		});


		var tgridObj = {
			init: function () {
				$('#datatable').tgrid({
					columns: tgridObj.columns,
					checkbox: true,
					url: global.adminPath + '/category/datapage'
				});
			},
			load: function () {
				var params = {};
				params = $('#query_form').serializeJSON();
				$('#datatable').tgrid('load', params);
			},
			columns: [{
				width: '80',
				align: 'center',
				title: '栏目名称',
				field: 'categoryName'
			}, {
				width: '80',
				title: '上级栏目',
				align: 'center',
				field: 'perentName'
			}, {
				width: '30',
				title: '显示栏目',
				align: 'center',
				field: 'showModes',
				formatter: function (value, row, index) {
					if (value == 0) {
						return '隐藏';
					} else {
						return '显示';
					}

				}
			}, {
				width: '80',
				align: 'center',
				title: '排序',
				field: 'categoryOrder'
			}],
			add: function () {
				var url = global.adminPath + '/category/addview';
				layer_show('添加', url, 800, 500);
			},
			edit: function () {
				var obj = $('#datatable').tgrid('getSelections');

				if (obj.length != 1) {
					layer.alert('请选择一条', {
						icon: 7
					});
					return false;
				}

				var url = global.adminPath + '/category/edit/' + obj[0].categoryId;
				layer_show('编辑', url, 800, 500);
			},
			del: function () {

				var obj = $('#datatable').tgrid('getSelections');

				if (obj.length != 1) {
					layer.alert('请选择一条', {
						icon: 7
					});
					return false;
				}

				layer.confirm('确认要删除吗？', function (index) {
					var data = {};
					$.ajax({
						type: "POST",
						data: data,
						dataType: 'json',
						url: global.adminPath + '/category/delete/' + obj[0].categoryId,
						success: function (res) {
							if (res.success) {
								tgridObj.load();
								layer.alert('已删除!', {
									icon: 1
								});
							} else {
								layer.alert(res.message, {
									icon: 2
								});
							}
						}
					});


				});
			}

		}



	</script>
</body>

</html>